var configCommon = {
    apiServer: "http://www.ganziyy.cn/AppApi", //接口地址
    pic: "http://www.ganziyy.cn/" //图片地址
}
var isAndroid = navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Adr') > -1; //android终端
var isiOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
var clickevent = isiOS ? "tap" : "click";

var sendByUrl = function(api, parameters, success, error) {
    $.ajax({
        url: configCommon.apiServer + api,
        data: parameters,
        type: "get",
        cache: false,
        dataType: "json",
        headers: {},
        timeout: 600000,
        success: function(data, textStatus, jqXHR) {
            success && success(data);
        },
        complete: function(response, data) {},
        error: function(jqXHR, textStatus, errorThrown) {
            if (jqXHR.status == 401) {
                location.href = contextPath + '/index';
            } else {
                if (!errorThrown) {
                    return false;
                }
                var errors = {
                    101: "网络不稳定或不畅通，请检查网络设置",
                    403: "服务器禁止此操作！",
                    500: "服务器遭遇异常阻止了当前请求的执行<br/><br/><br/>"
                };
                var msg = null;
                switch (textStatus) {
                    case "timeout":
                        msg = "网络连接超时，请检查网络是否畅通！";
                        break;
                    case "error":
                        if (errors[jqXHR.status]) {
                            var data = null;
                            try {
                                data = jQuery.parseJSON(jqXHR.responseText);
                            } catch (e) {}
                            if (data && data.message) {
                                msg = data.message;
                            } else {
                                msg = errors[jqXHR.status];
                            }
                        } else {
                            msg = "服务器响应异常<br/><br/>" + (jqXHR.status == 0 ? "" : jqXHR.status) + "&nbsp;" + errorThrown;
                        }
                        break;
                    case "abort":
                        msg = null; //"数据连接已被取消！";
                        break;
                    case "parsererror":
                        msg = "数据解析错误！";
                        break;
                    default:
                        msg = "出现错误:" + textStatus + "！";
                }
                if (errorThrown.code != null && errorThrown.message != null && !errors[errorThrown.code]) {
                    msg += "</br>[code:" + errorThrown.code + "][message:" + errorThrown.message + "]" + (null == errorThrown.stack ? "" : errorThrown.stack);
                }
            }
        }
    });
};
var $C = {

}
$C.query = function(href) {
    var args = {},
        queryArr = [],
        queryArrItem = [],
        name, value,
        href = href || window.location.href,
        queryStr = href.split("?")[1] ? href.split("?")[1].split("#")[0] ? href.split("?")[1].split("#")[0] : "" : "";
    if (queryStr == "") {
        return {};
    } else {
        queryArr = queryStr.split("&");
        for (var i = queryArr.length - 1; i >= 0; i--) {
            queryArrItem = queryArr[i].split("=");
            name = decodeURIComponent(queryArrItem[0]);
            value = decodeURIComponent(queryArrItem[1]);
            args[name] = value || "";
        };
        return args;
    };
};

function setCookie(name, value) {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) {
        return unescape(arr[2]);
    } else {
        return null;
    }
}
//;
// //热门新闻
// var GetHotNews = function(data, callback){
//     sendByUrl("/GetHotNews", data, callback);
// }
//
// varGetHotNews: (data, callback) => send("get", ),
//     GetCultureNews: (data, callback) => send("get", "/GetCultureNews", data, callback), //民俗
//     GetSingerInfo: (data, callback) => send("get", "/GetHotSinger", data, callback) //歌手
function getDriver(adress) {
    var local = "四川省";
    var map = new BMap.Map("container");
    //map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
    //map.centerAndZoom(local, 15);
    //map.addControl(new BMap.NavigationControl());
    map.addControl(new BMap.ScaleControl());

    var myGeo = new BMap.Geocoder(),p2,p1;
    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function(r){
        if(!r){
            $("#container").html("无效地址");
            return false;
        }
        p1 = new BMap.Point(r.point.lng,r.point.lat);
        map.addOverlay(new BMap.Marker(p1));
        map.centerAndZoom(p1, 15);

        myGeo.getPoint(adress, function(point){
            if(!point){
                $("#container").html("无效地址");
                return false;
            }
            p2 = point;
            // var newmarker=new BMap.Marker(new BMap.Point(point.lng,point.lat));
            // map.addOverlay(newmarker);
            var driving =new BMap.DrivingRoute(map, {
                renderOptions: {
                    map: map,
                    autoViewport: true,
                    panel: "r-result"
                }
            });
            driving.search(p1,p2);
            driving.setSearchCompleteCallback(function(){
                var pts = driving.getResults().getPlan(0).getRoute(0).getPath();    //通过驾车实例，获得一系列点的数组
                var polyline = new BMap.Polyline(pts);
                map.addOverlay(polyline);

                var lab1 = new BMap.Label("起点",{position:p1});       //创建2个label
                var lab2 = new BMap.Label("终点",{position:p2});
                map.addOverlay(lab1);
                map.addOverlay(lab2);
                setTimeout(function(){
                    map.setViewport([p1,p2]);          //调整到最佳视野
                },1000);
            });
        },local);
    },{enableHighAccuracy: true});
}
//title:"测试title",
//                 subtitle:"测试subtitle",
//                 url:"www.baidu.com",
//                 logo:"http://www.ganzixinwen.com/uploads/file/2017/0731/20170731092405573.png",
//                 shareto:id
function shareInfo(shareTitle,subtitle,url,logo,id) {
    console.log(shareTitle+subtitle+url+logo+id);
    try{
        window.android.H5Share(shareTitle, subtitle, url, logo, id);
    }catch (e){
        try{
            window.H5Share(shareTitle, subtitle, url, logo, id);
        }catch(e){
            alert("暂不支持分享"+e);
        }
    }
}
function openWebInfoUrl(url) {
    if(url && url != ''){
        try{
            window.android.webInfo(url);
        }catch (e){
            try{
                window.webInfo(url);
            }catch (e){
                location.href = url;
            }
        }
    }
}
var _hmt = _hmt || [];
window.addEventListener("load",function(){
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?994d91270a2b156c023a3f314786d5fe";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
})